package com.briup.upload.config;

import com.briup.common.properties.UploadConfigProperties;
import com.briup.upload.service.IRecoverImageService;
import com.briup.upload.service.IUploadService;
import com.briup.upload.service.impl.RecoverImageServiceImpl;
import com.briup.upload.service.impl.UploadServiceImpl;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * 上传模块，配置类
 */
@ComponentScan({"com.briup.upload.web.controller"})
@Configuration
@Data
public class UploadAutoConfig {

	@Autowired
	private UploadConfigProperties uploadConfigProperties;

	@ConditionalOnMissingBean(IUploadService.class)
	@Bean
	public IUploadService uploadServiceImpl(){
		return new UploadServiceImpl(uploadConfigProperties.getBastPath(),uploadConfigProperties.getUploadType());
	}

	@ConditionalOnMissingBean(IRecoverImageService.class)
	@Bean
	public IRecoverImageService recoverImageServiceImpl(){
		return new RecoverImageServiceImpl(uploadConfigProperties.getBastPath(),uploadConfigProperties.getUploadType(),uploadConfigProperties.getBaseRecoverDir());
	}
}
